package demo.gl;

import java.nio.*;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
public class background {
	private FloatBuffer fb;
	private ShortBuffer sb;
	private FloatBuffer cb;
	private float kcX=0.2f;
	private float kcY=0.2f;
	private float doday=0.1f;
	private float toadodiem[]={
			-kcX/2, -kcY/2, -doday, //1
			kcX/2, -kcY/2, -doday, 	//2
			kcX/2, kcY/2, -doday, 	//3
			-kcX/2, kcY/2, -doday, 	//4
			-kcX/2, -kcY/2, doday, 	//5
			kcX/2, -kcY/2, doday, 	//6
			kcX/2, kcY/2, doday, 	//7	
			-kcX/2, kcY/2, doday	//8	

		};

	private short ThuTuVe[]={
			0, 4, 5,    0, 5, 1,
	        1, 5, 6,    1, 6, 2,
	        2, 6, 7,    2, 7, 3,
	        3, 7, 4,    3, 4, 0,
	        4, 7, 6,    4, 6, 5,
	        3, 0, 1,    3, 1, 2,
	        };
	private float color[]={
			0.0f, 0.5f, 1.0f,1.0f,
			0.5f, 0.5f, 0.0f,1.0f,
			0.5f, 0.5f, 1.0f,1.0f,
			0.0f, 1.0f, 0.5f,1.0f,
			0.0f, 0.5f, 1.0f,1.0f,
			0.5f, 0.5f, 0.0f,1.0f,
			0.5f, 0.5f, 1.0f,1.0f,
			0.0f, 1.0f, 0.5f,1.0f

	};
	float yellow[]={
			1.0f, 1.0f, 0.0f,0.1f,
			1.0f, 1.0f, 0.0f,0.1f,
			1.0f, 1.0f, 0.0f,0.1f,
			1.0f, 1.0f, 0.0f,0.1f,
			1.0f, 1.0f, 0.0f,0.1f,
			1.0f, 1.0f, 0.0f,0.1f,
			1.0f, 1.0f, 0.0f,0.1f,
			1.0f, 1.0f, 0.0f,0.1f
	};
	public background(int x,int y,int color1){
		if (color1==1)
		{
		ByteBuffer vbb=ByteBuffer.allocateDirect(color.length*4);
		vbb.order(ByteOrder.nativeOrder());
		cb=vbb.asFloatBuffer();
		cb.put(color);
		cb.position(0);
		}
		else
		{
			ByteBuffer vbb=ByteBuffer.allocateDirect(yellow.length*4);
			vbb.order(ByteOrder.nativeOrder());
			cb=vbb.asFloatBuffer();
			cb.put(yellow);
			cb.position(0);
			
		}
		float offsety=((x-6)*kcX)+(kcX/2);
		float offsetx=((y-6)*kcY)+(kcY/2);
		
		for (int i=0;i<8;i++)
		{

			toadodiem[3*i]=toadodiem[3*i]+offsetx;
			toadodiem[3*i+1]=-(toadodiem[(3*i)+1]+offsety);
		}
		init();
		
	}
	public background(){
		
		init();
	}

	public void init()
	{
		ByteBuffer bb=ByteBuffer.allocateDirect(toadodiem.length*4);//
		bb.order(ByteOrder.nativeOrder());
		fb=bb.asFloatBuffer();
		fb.put(toadodiem);
		fb.position(0);
		 
		ByteBuffer vebb=ByteBuffer.allocateDirect(ThuTuVe.length*4);
		vebb.order(ByteOrder.nativeOrder());
		sb=vebb.asShortBuffer();
		sb.put(ThuTuVe);
		sb.position(0);
		

	}
	public void Draw(GL10 gl){
		gl.glFrontFace(GL10.GL_CW);
		gl.glVertexPointer(3, GL10.GL_FLOAT, 0, fb);
		gl.glColorPointer(4, GL10.GL_FLOAT, 0, cb);
		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
		gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
		gl.glDrawElements(GL10.GL_TRIANGLES,36, GL10.GL_UNSIGNED_SHORT, sb);
		gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
		gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
	}
	
	
}
